package com.smalltao.sso.controller;

import com.smalltao.core.base.controller.BaseController;
import com.smalltao.core.base.result.Result;
import com.smalltao.sso.dao.MenuRepository;
import com.smalltao.sso.dao.RoleMenuRepository;
import com.smalltao.sso.dao.UserRoleRepository;
import com.smalltao.sso.entity.User;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author smallTao.liu
 * @version V1.0
 * @description
 * @date 2018/11/29 13:20
 */
@RestController
public class LayoutController extends BaseController {

    @Autowired
    private UserRoleRepository userRoleRepository;

    @Autowired
    private RoleMenuRepository roleMenuRepository;

    @Autowired
    private MenuRepository menuRepository;

    @GetMapping("/menu")
    public Result menuList() {
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        List roleIdList = userRoleRepository.findRoleUidByUserUid(user.getUid());
        List menuIdList = roleMenuRepository.findMenuUidByRoleUid(roleIdList);
        List menuList = menuRepository.findAllById(menuIdList);
        return new Result().success(menuList);
    }

}
